package com.springboot.demo.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.querydsl.core.types.dsl.BooleanExpression;
import com.springboot.demo.domain.QTestEntity;
import com.springboot.demo.domain.TestEntity;
import com.springboot.demo.repository.TestRepository;

/**
 * Created by chenjf on 2017/1/18.
 */
@RestController
@RequestMapping("jpa")
public class TestController {

    @Autowired
    private TestRepository testRepository;

    /**
     * spring data jpa测试
     */
    @GetMapping("list")
    public void list(){
        List<TestEntity> list = testRepository.findAll();
        System.out.println(list.size());
    }
    
    /**
     * spring data jpa querydsl测试
     */
    @GetMapping("dsl")
    public void queryDsl(){
    	final String name = "chenjf";
    	BooleanExpression expression = QTestEntity.testEntity.name.eq(name);
    	TestEntity testEntity = testRepository.findOne(expression);
        System.out.println(testEntity);
    }
}
